package com.leet.code.lcof;

public class Code56_2 {
    public static void main(String[] args) {
        int[] nums = {3, 4, 3, 3};
        System.out.println(new Code56_2().singleNumber(nums));

    }

    public int singleNumber(int[] nums) {
        int[] is = new int[31];

        for (int i : nums) {
            for (int j = 0; j < 31; j++) {
                int x = i & 1;
                is[j] = is[j] + x;
                i = i >> 1;
            }
        }

        int r = 0;
        for (int j = 30; j >= 0; j--) {
            r = r << 1;
            if (is[j] % 3 == 1) {
                r = r | 1;
            }
        }

        return r;
    }

}
